<template>
  <!--会签管理-我的审批-材料结算详情弹窗-->
  <j-modal :title="title" :width="width" :visible="visible" switchFullscreen @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': pageType === 'approver'?false:true} }"
    :cancelButtonProps="{ class:{'jee-hidden': pageType === 'approver'?false:true} }" @cancel="close" okText="提交">
    <template v-if="pageType === 'history'">
      <div v-if="list && list.length>0">
      <a-tabs type="card" @change="callback">
        <a-tab-pane  v-for="(item,index) in list" :key="index+1" :tab="'第'+(index+1)+'次审批'">
          <!-- <wt-xiangmuxiang-form ref="realForm2" :disabled="disableSubmit2" :defaultModel="item"></wt-xiangmuxiang-form> -->
          <wt-cailiaoshenpi-form ref="realForm2" :disabled="disableSubmit" :defaultModel="item"></wt-cailiaoshenpi-form>
        </a-tab-pane>
      </a-tabs>
      </div>
      <div v-else style="height:400px">暂无审核记录</div>
    </template>
    <template v-else>
      <wt-cailiaoshenpi-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit"
        @handleOpen="handleOpen"></wt-cailiaoshenpi-form>
    </template>
    <template #footer>
      <a-button v-if="!(pageType === 'approver'?false:true)" key="back" @click="handleCancel">取消</a-button>
      <a-popconfirm v-if="!(pageType === 'approver'?false:true)" title="确定驳回吗？" @confirm="handleReject"><a-button key="reject" type="primary" style="background: red;color: white;border: 1px solid red;">驳回</a-button></a-popconfirm>
      <a-popconfirm v-if="!(pageType === 'approver'?false:true)" title="确定同意吗？" @confirm="handleAgree"><a-button key="submit" type="primary">同意</a-button></a-popconfirm>
    </template>
  </j-modal>
</template>

<script>
  import WtCailiaoshenpiForm from './WtCailiaoshenpiForm'
  import {
    httpAction,
    getAction
  } from '@/api/manage'
  export default {
    name: 'WtyiShenpiModal',
    components: {
      WtCailiaoshenpiForm,
    },
    data() {
      return {
        title: '',
        width: 1000,
        visible: false,
        disableSubmit: false,
        disableSubmit1: true,
        pageType: 'detail', //detail-详情 approver-审批 edit-编辑
        url: {
          detail: '/countersign/wtCountersignProjectContract/queryByApprovNumber',
          edit: '',
          approver: '',
          queryById: '',
        },
        list: [],
      }
    },
    methods: {
      add() {
        this.visible = true
        this.$nextTick(() => {
          this.$refs.realForm.add();
        })
      },
      edit(record, type) {
        if (!!type) {
          this.pageType = type;
        }
        this.visible = true
        if (this.pageType === 'history') {
          this.getHistoryData(record);
        } else {
          this.$nextTick(() => {
            this.$refs.realForm.edit(record, type);
            this.disableSubmit = true;
          })
        }
        this.$forceUpdate();
      },
      //获取历史记录
      getHistoryData(record) {
        var that = this;
        getAction(`/wtCountersign/countersignMaterialStatement/queryByApprovNumber?approvNumber=${record.approvNumber}`)
          .then((res) => {
            if (res.success) {
              this.list = res.result;
            }
          })
      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOk() {
        this.$refs.realForm.submitForm();
      },
      //驳回
      handleReject() {
        this.$refs.realForm.submitForm('3');
      },
      //同意
      handleAgree() {
        this.$refs.realForm.submitForm('2');
      },
      submitCallback() {
        this.$emit('ok');
        this.visible = false;
      },
      //查看原审核记录
      handleOpen(type) {
        this.$emit('handleOpen', type);
      },
      handleCancel() {
        this.close()
        // this.$refs.realForm1.edit();
      }
    }
  }
</script>